﻿using Fungus;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.mediation.impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace CommonIoC
{
    public enum FlowchartEvent
    {
        CHECK_TO_Talk,
        CHECK_TO_Search,
        Talk_TO_RedLangOne,
        Talk_TO_RedLangTwo,
        TalkToGet_1_Tank
    }

    public class FlowchartView : strange.extensions.mediation.impl.View
    {
        [Inject]
        public IEventDispatcher dispatcher { get; set; }

        public Flowchart flowchart;

        public void CloseAllUI_SetPlayerState()
        {
            dispatcher.Dispatch(MainUIEvent.CloseAllUI);
        }


        public void Set_TalkToBaBaOver()
        {
            //设置 拉多出已经与爸爸对话完毕了，，
            GameDataManager.Instance.SetTalkValue("拉多村2楼与爸爸对话", true);

            bool result = GameDataManager.Instance.GetTalkValueByKey("拉多村2楼与爸爸对话");
            Debug.Log("对话结果是：" + result);
        }


        public void Set_TalkToRedLangIsOver()
        {
            //设置 拉多出已经与爸爸对话完毕了，，
            GameDataManager.Instance.SetTalkValue("拉多村南地洞与红狼对话", true);

            bool result = GameDataManager.Instance.GetTalkValueByKey("拉多村南地洞与红狼对话");
            Debug.Log("拉多村南地洞与红狼对话：" + result);
        }

        public void Set_TalkToRedLangOne()
        {
            GameObject.Find("NPCAutoContrl").GetComponent<FirstTankNPCCtl>().SetPlayer_TurnLeft();
            dispatcher.Dispatch( FlowchartEvent.Talk_TO_RedLangOne);
            //与战狗战斗后红狼提问是否一个人来
        }



        public void Set_TalkToGet_1_Tank()
        {
           // GameObject.Find("NPCAutoContrl").GetComponent<FirstTankNPCCtl>().SetPlayer_TurnLeft();
            dispatcher.Dispatch(FlowchartEvent.TalkToGet_1_Tank);
            //与战狗战斗后红狼提问是否一个人来
        }


        public void Set_TalkToGet_1_TankIsOver()
        {
            //设置 拉多出已经与爸爸对话完毕了，，
            GameDataManager.Instance.SetTalkValue("发现1号战车的对话", true);

            bool result = GameDataManager.Instance.GetTalkValueByKey("发现1号战车的对话");


            Debug.Log("发现1号战车的对话：" + result);
        }

        public void Set_PlayerDriveTank()
        {
            try
            {
                GameObject.Find("GameMainPlayer").GetComponent<BaseControlMove>().SetPlayerDriveTank();
                GameDataManager.Instance.SetPlayerToDriveTank();

            }
            catch
            {
                Debug.LogError("当前场景里面没有GameMainPlayer对象");
            }
        }

        public void Set_OpenPlayerMove()
        {
            try
            {
                GameObject.Find("GameMainPlayer").GetComponent<BaseControlMove>().OpenPlayerMove();
               // GameDataManager.Instance.SetPlayerToDriveTank();

            }
            catch
            {
                Debug.LogError("当前场景里面没有GameMainPlayer对象");
            }
        }

        public void Set_ClosePlayerMove()
        {
            try
            {
                GameObject.Find("GameMainPlayer").GetComponent<BaseControlMove>().ClosePlayerMove();
                // GameDataManager.Instance.SetPlayerToDriveTank();

            }
            catch
            {
                Debug.LogError("当前场景里面没有GameMainPlayer对象");
            }
        }



        /// <summary>
        /// 红狼说完那么你来处理那辆战车吧，离开，
        /// </summary>
        public void SayEndWalkDownToPointA()
        {
            try
            {
                GameObject.Find("NPCAutoContrl").GetComponent<FirstTankNPCCtl>().SendFSM_RedTankMoveToAAA();
            }
            catch
            {
                Debug.LogError("当前场景里面没有NPCAutoContrl对象");
            }
        }
        /// <summary>
        /// 红狼提问是否一个人来对话之后，开战车往左行驶
        /// </summary>
        public void SayRedTankDriveLeft()
        {
            try
            {
                GameObject.Find("NPCAutoContrl").GetComponent<FirstTankNPCCtl>().SendFSM_RenLangDriveCarLeft();
            }
            catch
            {
                Debug.LogError("当前场景里面没有NPCAutoContrl对象");
            }
        }

        /// <summary>
        /// 红狼说完，是辆破车，副炮没有了之后，要往下走返回坦克
        /// </summary>
        public void SayBadTank_WalkDown()
        {
            try
            {
                GameObject.Find("NPCAutoContrl").GetComponent<FirstTankNPCCtl>().SendFSM_RenLangWalkDown_TwoStep_BackTank();
            }
            catch
            {
                Debug.LogError("当前场景里面没有NPCAutoContrl对象");
            }
        }


        public void DestoryTank_1_Object()
        {
            try
            {
                GameObject.Find("NPCAutoContrl").GetComponent<FirstTankNPCCtl>().DestoryTank_1_Object();
            }
            catch
            {
                Debug.LogError("当前场景里面没有NPCAutoContrl对象");
            }
        }


        public void Set_TalkToRedLangTwo()
        {
            dispatcher.Dispatch(FlowchartEvent.Talk_TO_RedLangTwo);
            //与战狗战斗后红狼提问是否一个人来
        }


        public void IsDoingTalk()
        {
            dispatcher.Dispatch(PlayerGameState.IsDoingTalk);
        }

        public void IsEndTalk()
        {
            dispatcher.Dispatch(PlayerGameState.CanMove_And_CanTouchWSAD);
        }



    }
}
